---@class replica_components
---@field webbert_seedbox replica_webbert_seedbox

---@class replica_webbert_seedbox
---@field inst ent_webbert_seedbox
---@field info netvar
---@field map table<PrefabID,integer> # 种子: 数量
---@field loaded boolean
local webbert_seedbox = Class(

---@param self replica_webbert_seedbox
---@param inst ent_webbert_seedbox
function(self, inst)
    self.inst = inst
    self.info = net_string(inst.GUID, "webbert_seedbox.info",'webbert_seedbox_info_change')
    self.map = {}
    inst:ListenForEvent("webbert_seedbox_info_change", function()
        self:Decode()
        -- 更新ui
        if inst.webbert_seedbox_isopen then
            local refer = inst.webbert_seedbox_containerwidget
            if refer and refer.webbert_seedbox_scrolllist_item_map then
                for seed,num in pairs(self.map) do
                    -- local i = refer.check_map_webbert_seedbox_scrolllist_item[seed] or nil
                    -- if i and refer.webbert_seedbox_scrolllist.items[i] then
                    --     refer.webbert_seedbox_scrolllist.items[i]:SetSeedsNum(num)
                    -- end
                    local member = refer.webbert_seedbox_scrolllist_item_map[seed] or nil
                    if member then
                        member:SetSeedsNum(num)
                    end
                end
            end
        end
    end)
    self.loaded = false
end)

function webbert_seedbox:Decode()
    local val = self.info:value()
    ---@cast val string
    local values = string.split(val, "|")
    for i = 1, #values, 2 do
        if values[i] and values[i+1] then
            self.map[values[i]] = tonumber(values[i+1])
        end
    end
end

return webbert_seedbox